package com.zhiqingchun.common;

public class Page {

	private int pageNumber = 5;// 每页显示数量
	private int recordCount = 0;// 总记录显示
	private int pageCount = 1;// 总页数
	private int pageIndex = 1;// 当前页数编号
	public int getPageNumber() {
		return pageNumber;
	}
	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}
	public int getRecordCount() {
		return recordCount;
	}
	public void setRecordCount(int recordCount) {
		this.recordCount = recordCount;
	}
	public int getPageCount() {
		this.pageCount=this.recordCount/this.pageNumber;
		if(this.recordCount%this.pageNumber!=0){
			this.pageCount++;
		}
		return pageCount;
	}
	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}
	public int getPageIndex() {
//		return pageIndex;
//		按orange
		//pageIndex不能小于1
		//pageIndex通过page.tag的input提交到action，
		//然后action层调用dao层，dao层设置了page的recordCount,
		//然后页面要显示时，会调用
		getPageCount();
		if (pageIndex > pageCount) {
			pageIndex = pageCount;
		}
		//注意当没有记录时，pageCount有可能是0，所以上一句pageIndex会被设为0
		//但pageIndex不应该小于1，所以<1的条件判断应该放在最后
		if (pageIndex < 1) {
			this.pageIndex = 1;
		}
		return pageIndex;
		
	}
	public void setPageIndex(int pageIndex) {
//		if (pageIndex > this.pageCount) 
//			this.pageIndex = 1;
//		else if (pageIndex < 1)
//			this.pageIndex = this.pageCount;
//		else
			this.pageIndex = pageIndex;
	}
}
